<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

include ("../conn/conn.php");
$conn = prepare();

$name = $_POST['name'];
$password = $_POST['password'];
$age = $_POST['age'];
$tel = $_POST['tel'];

if ($_POST['sex']==0) {
    $sex = '男';
} else {
    $sex = '女';
}

$sql= exectue_sql_statement($conn, "select * from Users where users_name='$name'");
$info=sqlsrv_fetch_array($sql);
if($info!=false){
 echo"<script>alert('该用户名已经存在!');window.location.href='addadmin.php';</script>";
exit;
}


exectue_sql_statement($conn, 
                      "insert into ".
                      "Users(users_name, users_password, users_sex, users_age, users_tel) ".
                      "values('$name', '$password', '$sex', $age, '$tel')"
                     );
echo "<script>alert('管理员".$name."添加成功!');window.location.href='addadmin.php';</script>";
?>